<template>
    <div class="table-data1" v-if="allDatas!==''"  style="display:block;">
    </div>
</template>

<script lang="ts">
    import { Component, Vue, Provide } from "vue-property-decorator";
    // import { State, Getter, Mutation, Action } from "vuex-class";
    // import EditDialog from "./editDialog.vue";
    import orderApi from "@/api/order";
    import Clipboard from 'clipboard'
    @Component({ components: {} })
    export default class orderDetail extends Vue {
        // @Getter("user") getUser: any;
        shipping_no: any = '';
        shipping_company: any = '';
        @Provide() state: boolean = false; // 黑白名单状态
        @Provide() isShip: boolean = false; // 物流商品
        @Provide() isWrite: boolean = false; // 核销商品
        @Provide() tHeight: number = document.body.offsetHeight - 323;
        @Provide() tableData: any = []; // 表格数据
        @Provide() tableDatas: any = []; // 表格数据
        @Provide() writeBtn: boolean = false; // 核销按钮
        @Provide() allDatas:any={
            order_info:{},
            shop_info:{},
            user_info:{}
        }
        @Provide() isAdd: Boolean = false; // 是否展示添加弹窗
        @Provide() submitData:{
            order_id: any,
            ids: string,
        }={
            order_id: "",
            ids: "",
        }
        @Provide() formData:any={
            id:"",
            shipping_company:"",
            shipping_no:""
        }
        created() {
            this.loadData();
        }
        // 复制单号
        handleCopy(com,nu){
            window.location.href = 'https://www.kuaidi100.com/chaxun?com='+[com]+'&nu='+[nu]
        }
        // 合并单元格
        objectSpanMethod({ row, column, rowIndex, columnIndex }) {
            if (columnIndex === 0) {
                for (let index in this.tableData) {
                    if(this.tableData[index].ticket!==undefined) {
                        if(rowIndex % this.tableData[index].ticket.length===0){
                            return{rowspan:row.length,colspan:1}
                        }else{
                            return{rowspan:0,colspan:0}
                        }
                    }

                }
            }
        }
        // 关闭弹窗
        closeDialog() {
            this.isAdd = false;
        }
        back(){
            this.$router.go(-1)
        }
        // 发货
        submitFahuo() {
            this.isAdd=true
            this.formData.id=this.$route.query.id
        }
        // 核销
        submitHexiao(){
            this.submitData.order_id=this.$route.query.id
            // this.submitData.ids
            this.tableDatas.forEach(item=>{
                this.submitData.ids+=item.id+','
            })
            this.submitData.ids=this.submitData.ids.substr(0, this.submitData.ids.length - 1)
            orderApi.writeOrder(this.submitData)
                .then((res: any) => {
                    this.$emit("closeDialog");
                    this.$emit("loadData")
                    if(res.data.status){
                        this.$message({
                            message: '操作成功',
                            type: "success"
                        });
                    }
                });
        }
        loadData() {
            orderApi.orderDetail(this.$route.query.id)
                .then((res: any) => {
                    if (res.data.code !== 200) {
                        this.$message({
                            message: res.data.msg,
                            type: "error"
                        });
                        history.back();
                        return false;
                    }
                    this.allDatas=res.data.data
                    if(res.data.data.shipping_info.shipping_no!==undefined) {
                        this.shipping_no = this.allDatas.shipping_info.shipping_no
                    }
                    if(res.data.data.shipping_info.shipping_company!==undefined) {
                        this.shipping_company = this.allDatas.shipping_info.shipping_company
                    }
                    if(this.allDatas.order_info.shipping_type_txt=="ship"){
                        this.isShip=true
                        this.isWrite=false
                        this.tableDatas=res.data.data.order_item
                    }else{
                        this.isShip=false
                        this.isWrite=true
                        this.tableData=res.data.data.order_item
                        let a:any=[]
                        if(this.allDatas.order_info.shipping_type_txt!='ship'){
                            if(this.allDatas.order_info.status=='wait' || this.allDatas.order_info.status=='wait_second'){
                                this.writeBtn=true
                            }
                        }
                        res.data.data.order_item.forEach(items => {
                            if(items.ticket){
                                items.ticket.forEach(item=>{
                                    item.cover=items.cover
                                    item.goods_name=items.goods_name
                                    item.channel_settle_price=items.channel_settle_price
                                    item.shop_settle_price=items.shop_settle_price
                                    item.spec_item=items.spec_item
                                    item.length=items.ticket.length
                                    a.push(item)
                                })
                            }else{
                                a.push(items)
                            }
                        });
                        this.tableDatas=a
                    }
                })
        }
    }
</script>

<style lang="scss" scoped>

    .el-table .cell, .el-table th div, .el-table--border td:first-child .cell, .el-table--border th:first-child .cell{
        padding: 0 !important;
    }
    .table-data1 {
        table{
            td{
                p{
                    border: 1px solid #EBEEF5;
                    width: 100%;
                }
            }
        }
        .order-detail-title{
            font-size: 16px;
            font-weight: bold;
            line-height: 40px;
            margin-top: 10px;
        }
        .user-info-item {
            width: 100%;
            display: flex;
            line-height: 24px;
            font-size: 14px;
            span {
                display: inline-block;
            }
            span:first-of-type {
                width: 150px;
                text-align: right;
            }
            span:last-of-type {
                padding-left: 15px;
            }
        }
    }
    .sub{
        text-align: center;
        margin: 50px 0;
    }
</style>
